<?php

class cv extends app_model {
  public $_key = 'url';
  public $_fields = array(
    'url' => array(
      'type' => 'VARCHAR(128)',
      'section' => 'Kontakt'),
    'anrede' => array(
      'type' => 'VARCHAR(64)',
      'section' => 'Kontakt'),
    'vorname' => array(
      'type' => 'VARCHAR(128)',
      'section' => 'Kontakt'),
    'nachname' => array(
      'type' => 'VARCHAR(128)',
      'section' => 'Kontakt'),
    'foto' => array(
      'type' => 'VARCHAR(128)',
      'access' => 'private',
      'widget' => 'image',
      'section' => 'Kontakt'),
    'strasse_nr' => array(
      'title' => 'Straße/Hausnr.',
      'type' => 'VARCHAR(128)',
      'display class' => 'street-address',
      'section' => 'Kontakt'),
    'plz' => array(
      'title' => 'PLZ',
      'type' => 'VARCHAR(10)',
      'display class' => 'postal-code',
      'section' => 'Kontakt'),
    'stadt' => array(
      'type' => 'VARCHAR(128)',
      'display class' => 'locality',
      'section' => 'Kontakt'),
    'land' => array(
      'type' => 'VARCHAR(64)',
      'display class' => 'country',
      'section' => 'Kontakt'),
    'status' => array(
      'type' => 'VARCHAR(64)',
      'default' => "z.B. suche Festanstellung ",
      'section' => 'Kontakt'),
    'telefon' => array(
      'type' => 'VARCHAR(128)',
      'access' => 'private',
      'section' => 'Kontakt'),
    'email' => array(
      'title' => 'E-Mail',
      'type' => 'VARCHAR(128)',
      'access' => 'private',
      'section' => 'Kontakt'),
    'password' => array(
      'title' => 'Passwort',
      'type' => 'VARCHAR(128)',
      'access' => 'private',
      'widget' => 'password',
      'sql' => 'PASSWORD(%s)',
      'section' => 'Kontakt'),
    'geburtstag' => array(
      'type' => 'DATE',
      'default' => 'JJJJ-MM-TT',
      'section' => 'Kontakt'),
    'zusammenfassung' => array(
      'type' => 'TEXT',
      //'widget' => 'fckeditor',
      'css id' => 'cte-summary',
      'section' => 'Überblick'),
    'kompetenz' => array(
      'type' => 'TEXT',
      //'widget' => 'fckeditor',
      'css id' => 'cte-competency',
      'section' => 'Überblick'),
    'last' => array(
      'type' => 'INT(11)'),
    'code' => array(
      'type' => 'VARCHAR(64)',
      'section' => 'Intern'),
    'publicity' => array(
      'title' => 'Veröffentlichung',
      'type' => "ENUM('directory', 'public', 'protected')",
      'widget' => array('select', array(
        'protected' => 'mit Kennwort',
        'public' => 'öffentlich')),
      'section' => 'Einstellungen'),
    'prot_passwd' => array(
      'title' => 'Kennwortschutz',
      'type' => 'VARCHAR(32)',
      'section' => 'Einstellungen'),
    'styling' => array(
      'type' => 'INT(11)',
      'widget' => array('select', array(
        -4 => 'Erde', 
        -3 => 'Luft',
        -2 => 'Wasser',
       // -1 => 'Feuer',
        /*0 => '-- eigenes --'*/)),
      'section' => 'Einstellungen'),
  );
  
  public $_has_many = array(
    'ausbildung' => array(
      'title' => 'Ausbildung',
      'model' => 'slot',
      'foreign_key' => 'url',
      'list' => array('title'),
      'item' => '_slot_full',
      'condition' => array('section = %s', 'ausbildung'),
      'order' => 'section, seq'),
    'beruf' => array(
      'title' => 'Berufserfahrung',
      'model' => 'slot',
      'foreign_key' => 'url',
      'list' => array('title'),
      'item' => '_slot_full',
      'condition' => array('section = %s', 'beruf'),
      'order' => 'section, seq'),
    );  
  
  function migration_2() {
    $sql = "ALTER TABLE `cv8`.`cv` MODIFY COLUMN `email` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
     ADD COLUMN `password` VARCHAR(128) NOT NULL AFTER `email`,
     ADD UNIQUE INDEX email(`email`);";
  }
  function migration_3() {
    $sql = "ALTER TABLE `cv8`.`cv` ADD COLUMN `last` INT(11), 
      ADD COLUMN `code` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci,
      ADD UNIQUE INDEX code(`code`);";
  }
  function migration_4() {
    $sql = "ALTER TABLE `cv8`.`cv` ADD COLUMN `status` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci,
      ADD UNIQUE INDEX status(`status`);";
  }
} 
